package com.itita.weibo.ui;


import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost;
import android.widget.Toast;

import com.itita.weibo.manager.IWeiboActivity;
import com.itita.weibo.util.WeiboUtil;


/**
 * 主要负责Tab间的切换
 * 
 * @author 焦明
 * 2010-4-24 9:57
 *
 */
public final class HomeActivity extends TabActivity implements IWeiboActivity{
	 
	public static boolean isSelected = false;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		WeiboUtil.closeWindowTitle(this);
		//各子页的加载
		this.setContentView(R.layout.maintabs);
		this.initControlsAndAddControlsEvent();
	}

	@Override
	public void initControlsAndAddControlsEvent() {
		//信息头部按钮
		final View  msgTitle=this.findViewById(R.id.msg_title);;
		//对消息的处理
		final Button btcomment=(Button)this.findViewById(R.id.bt_group_middle);
		//提示我的
		final Button btnMentionMe = (Button) this.findViewById(R.id.bt_group_left);
		//私信
		final Button btdirectmess=(Button)this.findViewById(R.id.bt_group_right);
		//完成各子页集成
		final TabHost th=this.getTabHost();
		//
		final RadioGroup mainGroup=(RadioGroup)this.findViewById(R.id.main_radio); 	
		//默认选中的哥选项
		
//		btnMentionMe.setSelected(true);
		
		//提到我的 微博列表
		btnMentionMe.setOnClickListener(new OnClickListener(){
			public void onClick(View v) {
				btnMentionMe.setSelected(true);
				btdirectmess.setSelected(false);
				btcomment.setSelected(false);
				
				Toast.makeText(HomeActivity.this, "提到我的", Toast.LENGTH_SHORT).show();
				MessageActivity.process.setVisibility(View.VISIBLE);
				
				MessageActivity.getAllMetionMe();	
			}
		});
		//评论
		btcomment.setOnClickListener(new OnClickListener(){
 	                 
					public void onClick(View v) {
					  btnMentionMe.setSelected(false);
					  btdirectmess.setSelected(false);
					  btcomment.setSelected(true);
					  
					  Toast.makeText(HomeActivity.this, "对我的评论", Toast.LENGTH_SHORT).show();
					  MessageActivity.process.setVisibility(View.VISIBLE);
					   MessageActivity.getAllComment();	
					}
		});
		
		
		//私信
		btdirectmess.setOnClickListener(new OnClickListener(){
              
			public void onClick(View v) {
			    btnMentionMe.setSelected(false);
			    btdirectmess.setSelected(true);
			    btcomment.setSelected(false);
				Toast.makeText(HomeActivity.this, "我的私信", Toast.LENGTH_SHORT).show();
				MessageActivity.process.setVisibility(View.VISIBLE);
			    MessageActivity.getAlldirectMessage();	
             }
	
		});
		
		
		th.addTab(th.newTabSpec("TAB_HOME")
		   .setIndicator("TAB_HOME")
		   .setContent(new Intent(this,MyListActivity.class))
		  );
		th.addTab(th.newTabSpec("TAB_MSG")
				   .setIndicator("TAB_MSG")
				   //MessageActivity.................................
				   .setContent(new Intent(this,MessageActivity.class))
				  );
		th.addTab(th.newTabSpec("TAB_USER_INFO")
				   .setIndicator("TAB_USER_INFO")
				   .setContent(new Intent(this,UserInfoActivity.class))
				  );
		th.addTab(th.newTabSpec("TAB_SEARCH")
				   .setIndicator("TAB_SEARCH")
//				   .setContent(new Intent(this,SearchActivity.class))
				   .setContent(new Intent(this,ListRcemmendInfoActivity.class))
				  );
		th.addTab(th.newTabSpec("TAB_MORE")
				   .setIndicator("TAB_MORE")
				   .setContent(new Intent(this,MoreActivity.class))
				  );
		
		mainGroup.setOnCheckedChangeListener(new OnCheckedChangeListener(){
 	        
			public void onCheckedChanged(RadioGroup arg0, int rid) {
			 
			 Log.d("radiou group", "you selected="+rid);
			 switch(rid){
				case R.id.radio_button0:// 首页
					th.setCurrentTabByTag("TAB_HOME");
					msgTitle.setVisibility(View.GONE);
			 
					break;
				case R.id.radio_button1:// 信息
					th.setCurrentTabByTag("TAB_MSG");
					// ------->
					msgTitle.setVisibility(View.VISIBLE);
					 
					btcomment.setSelected(true);
					btdirectmess.setSelected(false);
					btnMentionMe.setSelected(false);
					
					Toast.makeText(HomeActivity.this, "对我的评论", Toast.LENGTH_SHORT).show();
					MessageActivity.process.setVisibility(View.VISIBLE);
					MessageActivity.getAllComment();
					break;
				case R.id.radio_button2:// 资料
					th.setCurrentTabByTag("TAB_USER_INFO");
					msgTitle.setVisibility(View.GONE);
					break;
				case R.id.radio_button3:// 搜索
					th.setCurrentTabByTag("TAB_SEARCH");
					msgTitle.setVisibility(View.GONE);
					break;
				case R.id.radio_button4:// 更多
					msgTitle.setVisibility(View.GONE);
					th.setCurrentTabByTag("TAB_MORE");
					break;
				}
			}
		});
	}
	
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();
	}
	 
	public void init() {
		// TODO Auto-generated method stub
		
	}
	 
	public void refresh(Object... param) {
		// TODO Auto-generated method stub
		
	}



	
}
